/**
* Trigger Name: ifulfillRestrictDeleteWTask
* Author: Accenture * Date: 02-Feb-2012 
* Requirement/Project Name: iFulfill 
* Requirement Description: Workflow task is used in workflow definition which is not Inactive.You cannot delete workflow task.
**/


trigger ifulfillRestrictDeleteWTask on Wokflow_Steps__c (before delete)
{
list<Wokflow_Steps__c> wfstepList = new list<Wokflow_Steps__c>();
list<Workflow_Definition__c> wdefinitionList = new list<Workflow_Definition__c>();
list<Workflow_Stage__c> wfstageList = new list<Workflow_Stage__c>();
Set<ID> wfId = new Set<Id>(); 
for(Wokflow_Steps__c f: trigger.old) 
{     
wfId.add(f.Wokflow_Stage_Name__c); 
system.debug('systemstage'+ f.Wokflow_Stage_Name__r.Workflow_Code__c);
system.debug('systemstep1111'+ f.Wokflow_Stage_Name__c);
} 

wfstageList =[Select id from Workflow_Stage__c where Workflow_Code__r.status__c !='Inactive' and id in :wfId]; 
//[Select Status__c from Workflow_Definition__c where id in(select Workflow_Code__c from Workflow_Stage__c where id in :wfID)  and (Status__c = 'Active'or Status__c ='Pending Inactivation') ];
//[select id from Workflow_Stage__c where Workflow_Code__c in (Select id from Workflow_Definition__c where (Status__c = 'Active'or Status__c ='Pending Inactivation')and id in :wfId )];
wfId.clear(); 
for(Workflow_Stage__c wfObj: wfstageList ) 
{     
wfId.add(wfObj.id); 
}   
for(Wokflow_Steps__c f: trigger.old) 
{      
if(wfID.contains(f.Wokflow_Stage_Name__c))      
{            
f.adderror('Workflow task is used in workflow definition which is not Inactive.You cannot delete workflow task.');      
}  
}
}